import { createSlice } from '@reduxjs/toolkit'
import defaults from '../defaults'

const { bgUrls, config, search, engines, bookmarks } = defaults

export const systemSlice = createSlice({
  name: 'system',
  initialState: {
    bgAni: '',
    bgUrl: bgUrls[0],
    bgUrls: bgUrls,
    config: config,
    search: search,
    engines: engines,
    bookmarks: bookmarks,
  },
  reducers: {
    setBgAni: (state, action) => {
      state.bgAni = action.payload
    },
    setBgUrl: (state, action) => {
      state.bgUrl = action.payload
    },
    setBgUrls: (state, action) => {
      state.bgUrls = action.payload
    },
    setConfig: (state, action) => {
      state.config = action.payload
    },
    setSearch: (state, action) => {
      state.search = action.payload
    },
    setEngines: (state, action) => {
      state.engines = action.payload
    },
    setBookmarks: (state, action) => {
      state.bookmarks = action.payload
    },
  },
})

//actions
export const systemActions = systemSlice.actions

//state
export const systemState = (state) => state.system

// reducer
export const systemReducer = systemSlice.reducer
